{%- assign taboolaPixels = storeConfig.taboola | strtoarray -%}
{% assign adwords = storeConfig.google_adwords_trace_id | strtoarray %}
{% assign tracking = storeConfig.google_analytics_trace_id | strtoarray %}
{% assign conversion = storeConfig.google_conversion_id | strtoarray %}

{%- assign bigo_pixels = storeConfig.bigo_pixel_id | strtoarray -%}
{%- assign vk_pixels = storeConfig.vkontakte | strtoarray -%}
{%- assign yandex_pixels = storeConfig.yandex | strtoarray -%}
{%- assign outbrain_pixels = storeConfig.outbrain | strtoarray -%}
{%- assign criteo_pixels = storeConfig.criteo_pixel_id | strtoarray -%}


<script type="text/javascript">
    //add_to_cart
    function callback_add_to_cart(ec_data) {
        console.log('callback_add_to_cart');
        console.log(ec_data);
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_add_to_cart(ec_data);
        {% endif %}
        {%- if storeConfig.bing_uet_id -%}
        callback_bing_add_to_cart(ec_data);
        {% endif %}
        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
            window['callback_facebook_add_to_cart'] && callback_facebook_add_to_cart(ec_data);
        {% endif %}
        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_add_to_cart(ec_data);
        {% endif %}
        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_add_to_cart(ec_data);
        {% endif %}
        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_add_to_cart(ec_data);
        {% endif %}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_add_to_cart(ec_data);
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_add_to_cart(ec_data);
        {% endif %}
        {%- if taboolaPixels -%}
            callback_taboola_add_to_cart(ec_data);
        {%- endif -%}

        callback_event_script_add_to_cart(ec_data);

        {% if bigo_pixels %}
            callback_bigo_add_to_cart(ec_data);
        {% endif %}

        {% if vk_pixels %}
            callback_vk_add_to_cart(ec_data);
        {% endif %}

        {% if yandex_pixels %}
            callback_yandex_add_to_cart(ec_data);
        {% endif %}

        {% if outbrain_pixels %}
            callback_outbrain_add_to_cart(ec_data);
        {% endif %}

        {% if criteo_pixels %}
            callback_criteo_add_to_cart(ec_data)
        {% endif %}

        } catch (e) {
        console.log(e);
        }
    }

    //remove_from_cart
    function callback_remove_from_cart(ec_data) {
        console.log('callback_remove_from_cart');
        console.log(ec_data);
        try {
      
        {%- if adwords or tracking or conversion -%}
        callback_google_remove_from_cart(ec_data);
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_remove_from_cart(ec_data);
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_remove_from_cart(ec_data);
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_remove_from_cart(ec_data);
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_remove_from_cart(ec_data);
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_remove_from_cart(ec_data);
        {%- endif -%}
        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai__remove_from_cart(ec_data);
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_remove_from_cart(ec_data);
        {%- endif -%}
        callback_event_script_remove_from_cart(ec_data);
        } catch (e) {
        console.log(e);
        }
    }

    {% comment %} 登陆 {% endcomment %}
    function callback_login() {
        console.log('callback_login');
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_login();
        {%- endif -%}
        {%- if storeConfig.bing_uet_id -%}
        callback_bing_login();
        {%- endif -%}
        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_login();
        {%- endif -%}
        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_login();
        {%- endif -%}
        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_login();
        {%- endif -%}
        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_login();
        {%- endif -%}
        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_login();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_login();
        {%- endif -%}
        callback_script_event_login();
        } catch (e) {
        console.log(e);
        }
    }

    {% comment %} 注册 {% endcomment %}
    function callback_sign_up() {
        console.log('callback_sign_up');
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_sign_up();
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_sign_up();
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_sign_up();
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_sign_up();
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_sign_up();
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_sign_up();
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_sign_up();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_sign_up();
        {%- endif -%}
        {%- if taboolaPixels -%}
            callback_taboola_sign_up();
        {%- endif -%}

        {% if bigo_pixels %}
            callback_bigo_sign_up();
        {% endif %}

        {% if vk_pixels %}
            callback_vk_sign_up();
        {% endif %}


        {% if yandex_pixels %}
            callback_yandex_sign_up();
        {% endif %}
        callback_event_script_sign_up();
        } catch (e) {
        console.log(e);
        }
    }

    {% comment %} 商品分享 {% endcomment %}
    function callback_share_product(ec_data, platform) {
        console.log('callback_share_product');
        console.log(ec_data);
        console.log(platform);
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_share_product(ec_data, platform);
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_share_product(ec_data, platform);
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_share_product(ec_data, platform);
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_share_product(ec_data, platform);
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_share_product(ec_data, platform);
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_share_product(ec_data, platform);
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_share_product(ec_data, platform);
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_share_product(ec_data, platform);
        {%- endif -%}

        callback_event_script_share_product(ec_data, platform);
        callback_base_share_product(ec_data, platform);
        } catch (e) {
        console.log(e);
        }
    }

    {% comment %} 创建新用户 订阅、注册、下单 所有有可能创建新用户的地方 {% endcomment %}
    function callback_generate_lead() {
        console.log('callback_generate_lead');
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_generate_lead();
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_generate_lead();
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_generate_lead();
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_generate_lead();
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_generate_lead();
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_generate_lead();
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_generate_lead();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_generate_lead();
        {%- endif -%}


        callback_event_script_generate_lead();
        } catch (e) {
        console.log(e);
        }
    }


    function callback_begin_checkout() {
        console.log('callback_begin_checkout');
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_begin_checkout();
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_begin_checkout();
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_begin_checkout();
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_begin_checkout();
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_begin_checkout();
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_begin_checkout();
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_begin_checkout();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_begin_checkout();
        {%- endif -%}
        {%- if taboolaPixels -%}
            callback_taboola_begin_checkout();
        {%- endif -%}
        
        {% if bigo_pixels %}
            callback_bigo_begin_checkout();
        {% endif %}

        {% if outbrain_pixels %}
            callback_outbrain_begin_checkout();
        {% endif %}

        callback_event_script_begin_checkout();
        } catch (e) {
        console.log(e);
        }
    }

    function callback_add_address_information() {
        console.log('callback_add_address_information');
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_add_address_information();
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_add_address_information();
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_add_address_information();
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_add_address_information();
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_add_address_information();
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_add_address_information();
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_add_address_information();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_add_address_information();
        {%- endif -%}

        callback_event_script_add_address_information();
        } catch (e) {
        console.log(e);
        }
    }

    function callback_add_shipping_information() {
        console.log('callback_add_shipping_information');
        try {
        {%- if adwords or tracking or conversion -%}
        callback_google_add_shipping_information();
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_add_shipping_information();
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_add_shipping_information();
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_add_shipping_information();
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_add_shipping_information();
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_add_shipping_information();
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_add_shipping_information();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_add_shipping_information();
        {%- endif -%}

        callback_event_script_add_shipping_information();
        } catch (e) {
        console.log(e);
        }
    }

    function callback_add_payment_information() {
        console.log('callback_add_payment_information');
        try {
        {%- assign adwords = storeConfig.google_adwords_trace_id | strtoarray -%}
        {%- assign tracking = storeConfig.google_analytics_trace_id | strtoarray -%}
        {%- assign conversion = storeConfig.google_conversion_id | strtoarray -%}
        {%- if adwords or tracking or conversion -%}
        callback_google_add_payment_information();
        {%- endif -%}

        {%- if storeConfig.bing_uet_id -%}
        callback_bing_add_payment_information();
        {%- endif -%}

        {%- assign facebook = storeConfig.facebook | strtoarray -%}
        {%- if facebook -%}
        callback_facebook_add_payment_information();
        {%- endif -%}

        {%- if storeConfig.pinterest_pixel_id -%}
        callback_pinterest_add_payment_information();
        {%- endif -%}

        {%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        callback_snapchat_add_payment_information();
        {%- endif -%}

        {%- assign pixels = storeConfig.tiktok_pixel_id | strtoarray -%}
        {%- if pixels and storeConfig.tiktok_developer_mode -%}
        callback_tiktok_add_payment_information();
        {%- endif -%}

        {%- assign pixels = storeConfig.kwai_pixel_id | strtoarray -%}
        {%- if pixels -%}
        callback_kwai_add_payment_information();
        {% endif %}

        {%- if storeConfig.yahoo_pixel_id -%}
        callback_yahoo_add_payment_information();
        {%- endif -%}

        {%- if taboolaPixels -%}
            callback_taboola_add_payment_information();
        {%- endif -%}
        callback_event_script_add_payment_information();
        } catch (e) {
        console.log(e);
        }
    }

    function callback_add_to_wishlist(ec_data) {
        console.log('callback_add_to_wishlist');
        try {
            {%  if adwords or tracking or conversion %}
            callback_google_to_wishlist(ec_data);
            {% endif %}

            {%  if storeConfig.bing_uet_id %}
            callback_bing_to_wishlist(ec_data);
            {% endif %}

            {% assign facebook = storeConfig.facebook | strtoarray %}
            {%  if facebook %}
            callback_facebook_to_wishlist(ec_data);
            {% endif %}

            {%  if storeConfig.pinterest_pixel_id %}
            callback_pinterest_to_wishlist(ec_data);
            {% endif %}

            {%  if storeConfig.snapchat_pixel_id | strtoarray %}
            callback_snapchat_to_wishlist(ec_data);
            {% endif %}

            {% assign pixels = storeConfig.tiktok_pixel_id | strtoarray %}
            {%  if pixels and storeConfig.tiktok_developer_mode %}
            callback_tiktok_to_wishlist(ec_data);
            {% endif %}

            {% assign pixels = storeConfig.kwai_pixel_id | strtoarray %}
            {%  if pixels %}
            callback_kwai_to_wishlist(ec_data);
            {% endif %}

            {% if vk_pixels %}
                callback_vk_to_wishlist(ec_data);
            {% endif %}

            {% if yandex_pixels %}
                callback_yandex_to_wishlist(ec_data);
            {% endif %}

            {%- if taboolaPixels -%}
                callback_taboola_to_wishlist(ec_data);
            {%- endif -%}

        } catch (e) {
            console.log(e);
        }
    }
</script>

{% include analysis_base %}

{%- if adwords or tracking or conversion -%}
{% include analysis_google %}
{%- endif -%}

{%- if pixel_config.bing_pixel == true -%}
{% include analysis_bing %}
{%- endif -%}

{%- if pixel_config.facebook_pixel == true -%}
{% include analysis_facebook %}
{%- endif -%}

{%- if pixel_config.pinterest_pixel == true -%}
{% include analysis_pinterest %}
{%- endif -%}

{%- if pixel_config.snapchat_pixel == true -%}
{% include analysis_snapchat %}
{%- endif -%}

{%- if pixel_config.tiktok_pixel == true -%}
{% include analysis_tiktok %}
{%- endif -%}

{%- if pixel_config.kwai_pixel_id == true -%}
{% include analysis_kwai %}
{%- endif -%}

{%- if pixel_config.yahoo_pixel == true -%}
{% include analysis_yahoo %}
{%- endif -%}


{%- if taboolaPixels -%}
{% include analysis_taboola %}
{%- endif -%}


{% if bigo_pixels %}
{% include "analysis_bigo",bigo_pixels:bigo_pixels %}
{% endif %}


{% if vk_pixels %}
    {% include "analysis_vk",vk_pixels:vk_pixels %}
{% endif %}
    
{% if yandex_pixels %}
    {% include "analysis_yandex",yandex_pixels:yandex_pixels %}
{% endif %}

{% if outbrain_pixels %}
    {% include "analysis_outbrain",outbrain_pixels:outbrain_pixels %}
{% endif %}

{% if criteo_pixels %}
    {% include "analysis_criteo",criteo_pixels:criteo_pixels %}
{% endif %}



{% include analysis_event_script %}

{% comment %}如果url有generate_lead参数  即代表有创建新用户{% endcomment %}
<script type="text/javascript">

{% if current_step == 'contact_information' and template == 'order_contact_information' %}
callback_begin_checkout();
{% endif %}
{% if template == 'orderonepage_index' %}
    callback_begin_checkout();
{% endif %}
{% if current_step == 'shipping_method' and template == 'order_shipping_method' %}
callback_add_address_information();
{% endif %}

{% if current_step == 'payment_method' and template == 'order_payment_method' %}
callback_add_shipping_information();
{% endif %}

{% if current_step == 'payment_gateway' and template == 'order_payment_gateway' %}
// button event
//callback_add_payment_information();
{% endif %}

{% if request_param.generate_lead %}
callback_generate_lead();
{% endif %}
</script>
